<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * 用户管理的控制器
 */
class Category extends CI_Controller {
	public function __construct()
	{
		parent::__construct();
		if(empty($_SESSION['id'])){
	      echo "0";
	      echo "<script src='/static/js/jquery.min.js?v=2.1.4'></script>";
	      echo "<script src='/static/js/layer/layer.js'></script>";
	      echo "<script>layer.msg('你还没有登录，请先登录',{icon:2});setTimeout(function(){window.location.href='/login';},1500)</script>";
	      exit;
	    }
	}
	/**
	 * 获取鱼的分类
	 */
	public function lists(){
		$data = $this->cate->lists();
		if($data){
			$reg = array(
				"status"=>'success',
				"reson"=>$data
			);
		}else{
			$reg = array(
				"status"=>'error',
				"reson"=>"获取分类信息失败"
			);
		}
		jEcho($reg);
	}

	//添加分类
	public function add(){
		$data = $this->input->post();
		// $data = array(
		// 	'name'=>"jiayu"
		// );
		$status = $this->cate->add($data);
		if($status){
			$reg = array(
				"status"=>'success',
				"reson"=>"添加分类成功"
			);
		}else{
			$reg = array(
				"status"=>'error',
				"reson"=>"添加分类失败"
			);
		}
		jEcho($reg);
	}

	//获取一条数据
	public function one(){
		$where = $this->input->post();
		$data = $this->cate->getOne($where);
		if($data){
			$reg = array(
				"status"=>'success',
				"reson"=>$data
			);
		}else{
			$reg = array(
				"status"=>'error',
				"reson"=>"获取分类信息失败"
			);
		}
		jEcho($reg);
	}


	//修改分类名称的方法
	public function editHandle(){
		$id = $this->input->post('id');
		$data = array(
			"name"=>$this->input->post('name')
		);
		if($this->cate->edit($id,$data)){
			$reg = array(
				"status"=>'success',
				"reson"=>"修改分类成功"
			);
		}else{
			$reg = array(
				"status"=>'error',
				"reson"=>"修改分类失败"
			);
		}
		jEcho($reg);
	}
}